package com.university.report.user.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.university.report.model.entity.Permission;
import com.university.report.model.vo.PermissionRolesUserVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Jinondo
 * @since 2021-06-09
 */
@Repository
public interface PermissionMapper extends BaseMapper<Permission> {


    String CloName="per.perm_id,per.perm_name,per.perm_tag,per.url,role.role_name,role.description,user.username,user.user_id";
    String querySql = "select "+CloName+" from t_permission as per ,t_role as role ,t_user as user ,t_user_role as user_role, t_role_permission as role_permission\n" +
            "where per.perm_id=role_permission.perm_id and role.role_id=role_permission.role_id and role.role_id=user_role.role_id and user.user_id=user_role.user_id";
    String wrapperSql = "SELECT * from ( " + querySql + " ) AS q ${ew.customSqlSegment}";
    @Select(wrapperSql)
    IPage<PermissionRolesUserVo> selectPermissionRolesUserVo(Page<PermissionRolesUserVo> page, @Param(Constants.WRAPPER) QueryWrapper<PermissionRolesUserVo> queryWrapper);

}
